package com.ys.controller.api.inter.sys;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ys.dto.DtreeDto;
import com.ys.entity.sys.SysRole;
import com.ys.service.sys.CommonApiService;
import com.ys.service.sys.SysRoleService;
import com.ys.util.ReqUtil;
import com.ys.vo.LayuiTableVoJA;
import com.ys.vo.R;

@Controller
@RequestMapping("/api/inter/sysRole")
public class ApiInterSysRoleController {
	
//	private static final Logger logger = Logger.getLogger(ApiAdminLoginController.class);
	
	@Autowired
	private SysRoleService sysRoleService;
	@Autowired
	private CommonApiService<SysRole> commonApiService;
	
	@RequiresPermissions("sysMenu:view")
	@RequestMapping("/search")
    @ResponseBody
	public LayuiTableVoJA search(Model model, HttpServletRequest request, HttpServletResponse response,
			@ModelAttribute SysRole cond,
			Long roleId
			){
		
		return commonApiService.searchLay(cond);
	}
	
	@RequestMapping("/dtreeOfRole")
    @ResponseBody
	public DtreeDto dtreeOfRole(Model model, HttpServletRequest request, HttpServletResponse response){
		return sysRoleService.dtreeOfRole();
	}
	
	@RequestMapping("/dtreeOfAuth")
    @ResponseBody
	public DtreeDto dtreeOfAuth(Model model, HttpServletRequest request, HttpServletResponse response,
			Long sysRoleId){
		
		return sysRoleService.dtreeOfAuth(sysRoleId);
	}
	
	/**
	 * 新增子角色
	 */
	@PostMapping("/addSubSysRole")
    @ResponseBody
	public R addSubSysRole(Model model, HttpServletRequest request, HttpServletResponse response,
			Long pid,
			String name){
		return sysRoleService.addSubSysRole(pid, name);
	}
	
	@RequestMapping("/editSysRole")
    @ResponseBody
	public R editSysRole(Model model, HttpServletRequest request, HttpServletResponse response,
			Long id,
			String name){
		
		return sysRoleService.editSysRole(id, name);
	}
	
}
